/* 
    封装所有的请求方法
*/

import axios from './myAxios';
import mockaxios from './mockAxios';

/**
 * 请求首页三级分类的方法
 * @returns   Promise
 * @author    221024
 */
export const ReqCategorizeList = () =>
  axios.get('/api/product/getBaseCategoryList');

/**
 * 请求首页轮播图的方法
 * @returns   Promise  []
 */
export const ReqSlideList = () => mockaxios.get('/slide');

/**
 * 请求首页楼层的方法
 * @returns  Promise  []
 */
export const ReqFloorList = () => mockaxios.get('/floor');

/**
 * 请求 搜索结果的方法
 * @param {*} params
 * @returns  Promise
 */
export const ReqSearchList = (params) => axios.post('/api/list', params);

/**
 * 通过id  获取商品详情 的请求方法
 * @param {*} id   string
 * @returns   Promise
 */
export const ReqGoods = (id) => axios.get(`/api/item/${id}`);

/**
 * 添加购物车的请求方法
 * @param {*} id
 * @param {*} num
 * @returns   Promise<null>
 */
export const ReqAddCart = (id, num) =>
  axios.post(`/api/cart/addToCart/${id}/${num}`);

/**
 * 请求  购物车数据的 方法
 * @returns   Promise<购物车数据>
 */
export const ReqCartList = () => axios.get('/api/cart/cartList');

export const ReqCheckedList = (skuID, isChecked) =>
  axios.get(`/api/cart/checkCart/${skuID}/${isChecked}`);

export const ReqAllCheckedList = (isChecked, skuIdList) =>
  axios.post(`/api/cart/batchCheckCart/${isChecked}`, skuIdList);

export const ReqDeleteList = (skuId) =>
  axios.delete(`/api/cart/deleteCart/${skuId}`);

export const ReqAllDelete = (skuIdList) =>
  axios.post('/api/cart/batchDeleteCart', skuIdList);

export const ReqCode = (phone) =>
  axios.get(`/api/user/passport/sendCode/${phone}`);

/**
 * 注册
 * @param {*} params    {phone   password  code}
 * @returns   Promise <null>
 */

export const ReqRegister = (params) => {
  // console.log(params);
  return axios.post('/api/user/passport/register', params);
};

export const ReqLogin = (parmas) => {
  return axios.post('/api/user/passport/login', parmas);
};

export const ReqUserInfo = () =>
  axios.get('/api/user/passport/auth/getUserInfo');

export const ReqLogout = () => axios.get('/api/user/passport/logout');

export const ReqTrade = () => axios.get('/api/order/auth/trade');

export const ReqAddress = () => mockaxios.get('/address');

export const ReqOrder = (tradeNo, params) =>
  axios.post(`/api/order/auth/submitOrder?tradeNo=${tradeNo}`, params);

export const ReqOrderId = (orderId) =>
  axios.get(`/api/payment/weixin/createNative/${orderId}`);
